﻿#region Copyright and License
/*==============================================================================
 *  Copyright (c) www.51mvc.com Corporation.  All rights reserved.
 * ===============================================================================
 * This code and information is provided "as is" without warranty of any kind,
 * either expressed or implied, including but not limited to the implied warranties
 * of merchantability and fitness for a particular purpose.
 * ===============================================================================
 * Licensed under the GNU General Public License (GPL) v2
 * http://www.51mvc.com/
 * Create By 小鱼(Leven)  - http://leven.com.cn
 * ==============================================================================*/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Infancy.Core.Container.Unity;

namespace Infancy.Core.Container {
    public static class ContainerManager {
        public static IContainer GetContainer() {
            return GetContainer("default");
        }

        public static IContainer GetContainer(string name) {
            return new UnityContainer(name);
        }

        private static IContainer repositoryContainer;
        private static IContainer serviceContainer;
        private static object lockObject = new object();

        public static IContainer Repository {
            get {
                if (repositoryContainer == null) {
                    lock (lockObject) {
                        if (repositoryContainer == null) {
                            repositoryContainer = new UnityContainer("Repository");
                        }
                    }
                }
                return repositoryContainer;
            }
        }

        public static IContainer Service {
            get {
                if (serviceContainer == null) {
                    lock (lockObject) {
                        if (serviceContainer == null) {
                            serviceContainer = new UnityContainer("Service");
                        }
                    }
                }
                return serviceContainer;
            }
        }
    }
}
